#! /usr/bin/python
# encoding=utf-8
# Created by Fenglu Niu on 2025/5/27 14:41
from typing import List

from sqlmodel import Session, select

import common
from api.entity import CaseApplyRecord


class CaseApplyRecordService(object):
    @staticmethod
    def create_apply_record(case_apply_records: List[CaseApplyRecord], session: Session, autocommit: bool = True):
        try:
            session.add_all(case_apply_records)
            if autocommit:
                session.commit()
        except Exception as e:
            common.get_logger().error('创建案件申请记录报错：{}', e)
            session.rollback()

    @staticmethod
    def list_apply_record(case_id, session):
        return session.exec(select(CaseApplyRecord).where(CaseApplyRecord.case_id == case_id)).all()